import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import useMyReducer from '../../reducer';
const Index = () => {
    const [citys] = useState(["北京", "上海", "广州", "深圳"]);
    const { dispatch } = useMyReducer();
    const navigate = useNavigate();
    const handleSetCitys = (item) => {
        dispatch({
            type: "changeCity",
            value: item
        })
        navigate(-1);
    }
    return (
        <div>
            {citys.map(item => {
                return (
                    <button key={item} onClick={() => { handleSetCitys(item) }}>{item}</button>
                )
            })}
        </div>
    );
}

export default Index;
